package main1
import (
	"encoding/csv"
	"encoding/json"
	"fmt"
	"os"
	"strings"
)

type dict struct {
	Value string `json:"value"`;
	Synonyms []string `json:"synonyms,[]string"`;
}

var fileHandler *os.File
func main()  {
	path := "./test3.csv";
	fileHandler,_ = os.OpenFile(path,os.O_RDONLY,os.ModeDevice)
	defer func() {
		if re := recover();re!=nil {
			fileHandler.Close()
		}
		fileHandler.Close()
	}()
	var arr [][]string;
	var data []dict;
	var info dict;
	reader := csv.NewReader(fileHandler)
	for arr,reader = read(reader);arr!=nil;{
		for _,val := range arr{
			info = dict{};
			strings.ToLower(val[0])
			info.Value = val[0];
			info.Synonyms = append(info.Synonyms, val[0]);
			data = append(data, info)
		}
		out1,_ := json.Marshal(data)
		fmt.Println(string(out1))

		os.Exit(0)
	}
}

func read(reader *csv.Reader) ([][]string,*csv.Reader){
	record,err := reader.ReadAll()

	if err!=nil {
		panic(err)
	}
	return record,reader;
}
